<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* 清除默认样式 */
    * {
      margin: 0;
      padding: 0;
    }
    ul,ol {
      list-style: none;
    }
    .lunbo {
      position: relative;
      width: 880px;
      height: 550px;
      border: 1px solid #333;
      margin: 20px auto;
    }
    .lunbo .pic li {
      position: absolute;
      left: 0;
      top: 0;
      width: 880px;
      height: 550px;
      display: none;
    }
    .lunbo .pic .current {
      display: block;
    }
    /* 按钮 */
    .lunbo .btn a {
      position: absolute;
      top: 50%;
      width: 40px;
      height: 40px;
      margin-top: -20px;
      background-color: rgba(255,255,255,0.3);
      font: 20px/40px "宋体";
      text-align: center;
      color: #fff;
      text-decoration: none;
      font-weight: bold;
    }
    .lunbo .btn .leftbtn {
      left: 20px;
    }
    .lunbo .btn .rightbtn {
      right: 20px;
    }
    .lunbo .btn a:hover {
      background-color: rgba(255,255,255,0.6);
    }
    /* 下标 */
    .lunbo .sub {
      position: absolute;
      left: 100px;
      bottom: 50px;
      width: 240px;
    }
    .lunbo .sub li {
      float: left;
      width: 20px;
      height: 20px;
      margin-right: 20px;
      background-color: rgba(255,255,255,0.4);
      font: 12px/20px "微软雅黑";
      text-align: center;
      color: #666;
      cursor: pointer;
    }
    .lunbo .sub .current {
      background-color: #fff;
    }
  </style>
</head>
<body>
  <!-- 轮播图大结构 -->
  <div id="lunbo" class="lunbo">
    <!-- 图片部分 -->
    <ul id="pic" class="pic">
      <li class="current"><img src="images/lunbo/c1.jpg"></li>
      <li><img src="images/lunbo/c2.jpg"></li>
      <li><img src="images/lunbo/c3.jpg"></li>
      <li><img src="images/lunbo/c4.jpg"></li>
      <li><img src="images/lunbo/c5.jpg"></li>
      <li><img src="images/lunbo/c6.jpg"></li>
    </ul>
    <!-- 按钮 -->
    <right class="btn">
      <a id="left" href="javascript:;" class="leftbtn">&lt;</a>
      <a id="right" href="javascript:;" class="rightbtn">&gt;</a>
    </right
    <!-- 小圆点 -->
    <ol id="sub" class="sub">
      <li class="current">1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ol>
  </div>
  <script>
    //获取元素
    var lunbo = document.getElementById("lunbo");
    var left = document.getElementById("left");
    var right = document.getElementById("right");
    var pic = document.getElementById("pic");
    var sub = document.getElementById("sub");
    var pics = pic.getElementsByTagName("li");
    var subs = sub.getElementsByTagName("li");
    //右按钮点击切换
    //设置一个下标
    var num = 0;
    //如果num到达0，或者num超出pics的长度，则重置num
    left.onclick = function(){
      num--;
      if(num <= 0){
        num = pics.length-1;
      }
      change();
    }
    //右按钮
    right.onclick = function(){
      rightEnter();
    }
    //下面小按钮
    for(var i = 0; i < subs.length; i++){
      subs[i].index = i;
      subs[i].onclick = function(){
        
        num = this.index;
        change();
      }
    }
    
    //自动轮播效果,从左向右
    var timer;
    timer = setInterval(function(){rightEnter()},2000)
    //鼠标以上清除定时器
    lunbo.onmouseover = function(){
      clearInterval(timer);
    };
    //鼠标移出继续计时器
    lunbo.onmouseout = function(){
      timer = setInterval(function(){rightEnter()},2000)
    }
    //右键点击循环是重复的
    function rightEnter(){
      num++;
      if(num > pics.length-1){
        num = 0;
      }
      change();
    }
    //排他思想，更换图片和小点
    function change(){
      for(var j = 0; j < subs.length; j++){
        subs[j].className = "";
        pics[j].className = "";
      }
      subs[num].className = "current";
      pics[num].className = "current";

    }
  </script>
</body>
</html>